home *** CD-ROM | disk | FTP | other *** search
- Path: news.primenet.com!ip125
- From: mcoplea@primenet.com (Marty R. Coplea)
- Newsgroups: comp.lang.c
- Subject: Simple i/o for my class
- Date: 30 Jan 1996 01:11:01 -0700
- Organization: Primenet
- Sender: root@primenet.com
- Message-ID: <4ekjql$5jl@nnrp1.news.primenet.com>
- X-Posted-By: ip125.phx.primenet.com
- X-Newsreader: News Xpress Version 1.0 Beta #4
-
- I am having a little trouble with a batting average program.
- It seems to take the input OK, but always returns a '0' for the Batting
- Average. Please look at the following code and make any suggestions. Thank
- you in advance for any assistance you can offer. (email perfered)
-
- /***********************************
- DESIGN:
- Prompt the user to enter the number of at bats and the number of hits.
- Calculate the batting average (number of hits / number of at bats)
- Print out the result with 3 significant places to the right of the
- decimal point and make sure that the average does not round up.
- Report the results back to the user.
-
- TEST PLAN:
- Large Number / Large Number (11,000 / 2,125)
- Large Number / Small Number (12,000 / 33)
- Small Number / Small Number (15 / 6)
- Large Number / Zero (12,121 / 0)
- Small Number / Zero (5 / 0)
-
- ************************************/
-
- #include <stdio.h>
-
- int
- main(void)
- {
- float avar, hvar; /*float variables(avar=At-bats,hvar=Hits */
- int Hitsint, Atbatsint; /* Integers with Hits and At Bats */
- float Avg; /* Results Batting Average */
-
- /* Prompt the user to input the data */
- printf("Enter the number of at-bats followed by hits: ");
- scanf("%f %f", &avar, &hvar);
-
- /* Convert to integers */
- Atbatsint = avar;
- Hitsint = hvar;
-
- /* Calculate the Batting Average */
- Avg = Hitsint/Atbatsint;
-
- /* Return results to user */
- printf("Batting Average = %.2f\n", Avg);
-
- return 0; /* We done */
- }
-
-
-